package com.neu.canteen.service.impl;

import com.neu.canteen.domain.Book;
import com.neu.canteen.domain.BookItem;
import com.neu.canteen.domain.Food;
import com.neu.canteen.service.BookService;
import com.neu.canteen.service.FoodService;

public class BookServiceImpl implements BookService{
	
	private FoodService foodService = new FoodServiceImpl();

	@Override
	public void createBook(int customerId, int[] foodId, int[] count) {
		
		//TODO 
		
		Book book = new Book();
		book.setCustomerId(customerId);
		book.setCustomerName("根据id从数据库获取");
		 
		book.setNum(System.currentTimeMillis()+customerId+"");
		
		
		
		BookItem bookItem = new BookItem();
		int totalPrice=0;
		for(int i=0;i<foodId.length;i++){
			Food food = foodService.findById(foodId[i]);
			
			bookItem.setFoodPrice(food.getPrice());
			bookItem.setFoodId(food.getId());
			bookItem.setBookNum(book.getNum());
			
			bookItem.setTotalCount(count[i]);
			bookItem.setItemPrice(bookItem.getTotalCount()*food.getPrice());
			
			
			//保存bookItem到数据库
			
			totalPrice = totalPrice + bookItem.getItemPrice();
		}
		book.setTotalPrice(totalPrice);
		
		//保存book
		
	}

}
